﻿using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Configuration.Json;
using System;
using System.Collections.Generic;
using System.Text;
using IConfiguration = Microsoft.Extensions.Configuration.IConfiguration;

namespace MT.Common.Helper
{
    public class ConfigHelper
    {
        static IConfiguration Configuration { get; set; }

        static ConfigHelper()
        {
            Configuration = new ConfigurationBuilder().Add(new JsonConfigurationSource { Path = "Config/appsettings.json", ReloadOnChange = true }).Build();
        }

        public static string GetSection(params string[] sections)
        {
            try
            {
                var val = string.Empty;
                for (var i = 0; i < sections.Length; i++)
                {
                    val += sections[i] + ":";
                }
                return Configuration[val.TrimEnd(':')];
            }
            catch (Exception)
            {
                return "";
            }
        }

        //public static string GetSection(string jsonPath,params string[] sections)
        //{
        //    try
        //    {
        //        Configuration = new ConfigurationBuilder().Add(new JsonConfigurationSource { Path = jsonPath, ReloadOnChange = true }).Build();
        //        var val = string.Empty;
        //        for (var i = 0; i < sections.Length; i++)
        //        {
        //            val += sections[i] + ":";
        //        }
        //        return Configuration[val.TrimEnd(':')];
        //    }
        //    catch (Exception)
        //    {
        //        return "";
        //    }
        //}
    }


}
